/* Copyright 2018 Istio Authors. All Rights Reserved.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *    http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#pragma once

#include "gmock/gmock.h"
#include "source/common/protobuf/protobuf.h"
#include "src/istio/authn/context.pb.h"

namespace Envoy {
namespace Http {
namespace Istio {
namespace AuthN {
namespace TestUtilities {

istio::authn::Payload CreateX509Payload(const std::string& user) {
  istio::authn::Payload payload;
  payload.mutable_x509()->set_user(user);
  return payload;
}

istio::authn::Payload CreateJwtPayload(const std::string& user, const std::string& presenter) {
  istio::authn::Payload payload;
  payload.mutable_jwt()->set_user(user);
  if (!presenter.empty()) {
    payload.mutable_jwt()->set_presenter(presenter);
  }
  return payload;
}

istio::authn::Result AuthNResultFromString(const std::string& text) {
  istio::authn::Result result;
  EXPECT_TRUE(Protobuf::TextFormat::ParseFromString(text, &result));
  return result;
}

} // namespace TestUtilities
} // namespace AuthN
} // namespace Istio
} // namespace Http
} // namespace Envoy
